package net.huashitong.common.util;

import com.sirdc.modules.utils.StringUtils;
import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;
import net.huashitong.common.entity.SysMessage;

import java.util.Map;

/**
 * 云片短信助手
 * https://www.yunpian.com/  注册
 */
public class YunpianSmsHelper {
    //替换成 短信 永泰政府专用  此key 仅供开发使用
    private static final String API_KEY = "b3232c91e3336d52ae80b73bb0a1cb91";

    public static  Result<SmsSingleSend> sendSms(SysMessage sysMessage) {
        if (StringUtils.isBlank(sysMessage.getEsType())) {
            return null;
        }
        YunpianClient clnt = new YunpianClient(YunpianSmsHelper.API_KEY);
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE, sysMessage.getEsReceiver());
        //param.put(YunpianClient.TEXT, String.format("【永泰招商】您的验证码是%s。如非本人操作，请忽略本短信",userSmsLog.getVaildCode()));
        param.put(YunpianClient.TEXT, sysMessage.getEsContent());
        return clnt.sms().single_send(param);

        //根据情况保存
        //userSmsLog.setSendTime(System.currentTimeMillis());
        //userSmsLog.setIsUse();

        //获取返回结果，返回码:r.getCode(),返回码描述:r.getMsg(),API结果:r.getData(),其他说明:r.getDetail(),调用异常:r.getThrowable()
        //账户:clnt.user().* 签名:clnt.sign().* 模版:clnt.tpl().* 短信:clnt.sms().* 语音:clnt.voice().* 流量:clnt.flow().* 隐私通话:clnt.call().*

    }

//    public static Result<VoiceSend>  sendSound(UserSmsLog userSmsLog){
//        YunpianClient clnt = new YunpianClient(SmsUtil.API_KEY);
//        if(StringUtils.isBlank(userSmsLog.getVaildCode())){
//            throw new RuntimeException("不支持过长语音内容");
//        }
//        Map<String, String> param = clnt.newParam(2);
//        param.put(YunpianClient.MOBILE, userSmsLog.getMoblie());
//        param.put(YunpianClient.CODE, userSmsLog.getVaildCode());
//       return clnt.voice().send(param);
//    }

//    public static void main(String[] args) {
//        String key = "AUTOCLEAR-ScoreRecord-";
//        String className = key.substring(key.indexOf("-")+1,key.lastIndexOf("-"));
//        System.out.println(className);
//    }

}
